﻿@{
    ViewBag.Title = "元素表列表页";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>
    .dv-left {
        width: 20%;
        float: left;
    }

    .dv-right {
        float: left;
        margin-left: 5px;
        width: 79%;
        /*background-color:*/
    }
</style>
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
        </div>
      
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_delete()"><i class="fa fa-pencil-square-o"></i>删除</a>

        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="toCS()"><i class="fa fa-pencil-square-o"></i>同步到模板编辑器</a>

        </div>
    </div>
</div>
@*<div class="gridPanel">
        <table id="gridList"></table>
    </div>*@

<div id="treeDiv" class="gridPanel dv-left">
    @Html.Action("YSList", "Blys")
</div>
<div id="Blys" class="gridPanel dv-right" style="background-color:#ffffff;">
    @Html.Action("Form", "Blys")
</div>


<script>
    function SetBlysHeight() {
        //debugger;
        var ctl = document.getElementById("Blys");
        if (ctl != null) {
            if (ctl.getAttribute("ismobiledevice") != "true") {
           
                var h = document.documentElement.clientHeight - ctl.offsetTop - 20;
                ctl.style.height = h + "px";
            }
            else {
                if (document.body.clientWidth < 400) {
                    document.getElementById("cboFileName").style.width = "100%";
                }
            }
        }
    }
    window.setTimeout(SetBlysHeight, 300);
    window.setInterval(SetBlysHeight, 1000);
    function btn_add() {
        $("#tijiao").html("新增");
        clearInput();
    }
    function clearInput()
    {
        $("#Blys form input").each(function () {
            $(this).val('');
        });

        //$(".screen-window form select").each(function () {
        //    $(this).val('');
        //});
    }
    function btn_edit() {
        if (!$('#form1').formValid()) {
            return false;
        }

        var flag = $("#tijiao").html();
        if (flag=="修改")
        {

        var keyValue = $("#Id").val();
        if (!!!keyValue) {
            $.modalAlert("请选中元素", 'warning');
            return;
        }
        var postData = $("#form1").formSerialize();
        
        $.submitForm({
            url: "/Blys/SubmitForm?keyValue=" + keyValue,
            param: postData,
            success: function () {
                $.modalMsg("修改成功", 'success');
                getYsTree();
                btn_add();
            }
        });
        } else {
            var key= "";
            var postData = $("#form1").formSerialize();
            $.submitForm({
                url: "/Blys/SubmitForm?keyValue=" + key,
                param: postData,
                success: function () {
                  
                    getYsTree();
                    btn_add();
                    $.modalMsg("新增成功", 'success');
                }
            });
        }

       

    }

    function GetFormJson(keyValue) {
        if (!!keyValue) {
            $.ajax({
                url: "/Blys/GetFormJson",
                data: { keyValue: keyValue },
                dataType: "json",
                success: function (data) {
                    $("#form1").formSerialize(data);
                }
            });
        }
    }

    //删除
    function btn_delete() {
        var delYSID = $("#Id").val();
        if (delYSID === undefined) {
            $.modalMsg("请选择要删除的元素", 'warning');
            return;
        }
        $.modalConfirm("确定要删除吗？",
            function (flag) {
                if (flag) {
                    $.najax({
                        url: "@Url.Action("DeleteForm", "Blys")",
                        dataType: "json",
                        data: { delYSID: delYSID },
                        type: "POST",
                        success: function () {
                            $.loading(false);
                            $.modalMsg("删除成功", 'success');
                            getYsTree();
                            btn_add();
                        }
                    });
                }
            });
    }
    function toCS() {
        $.najax({
            url: "@Url.Action("toCS", "Blys")",
        type: "POST",
        success: function () {
            $.loading(false);
            $.modalMsg("同步成功", 'success');
      
        }
    });
    }
</script>